﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinkCard.Model;
using LinkCard.Utils;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace CRM
{
    public partial class UsersList : System.Web.UI.Page
    {
      
        private int _totalRecords;
        private int nPageSize = 100;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataBindPaging();
            }

        }
        private void DataBindPaging()
        {

            try
            {
                string sFilter = "AND [Status] = 2";
                
                int curpage = 0;

                if (Request.QueryString["page"] != null)
                {
                    curpage = Convert.ToInt32(Request.QueryString["page"]);
                }
                else
                {
                    curpage = 1;
                }

                DataTable dt = DataHelper.LoadPageInSQL("CustomerList", curpage, nPageSize, ref _totalRecords, new SqlParameter("@Filter", sFilter));

                if (dt.Rows.Count > 0)
                {
                    int nPageCount;

                    if (_totalRecords % nPageSize == 0)
                    {
                        nPageCount = _totalRecords / nPageSize;
                    }
                    else
                    {
                        nPageCount = Convert.ToInt32(_totalRecords / nPageSize) + 1;
                    }

                    //if (nPageCount < 2) divPager.Visible = false;

                    //PagerShow.Text = hash1way.ShowPageNavigation(curpage, nPageCount);

                    msgList.DataSource = dt;

                    msgList.DataBind();
                    //msgNoData.Visible = false;

                }

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

    }
}